package com.alibaba.otter.manager.web.resource;

import com.alibaba.otter.manager.web.dto.RestResponse;
import com.alibaba.otter.manager.web.dto.TableStatDTO;
import com.alibaba.otter.manager.web.service.TableStatAggService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.time.Instant;

@RequestMapping("/api/v1/table-stat")
@RestController
public class TableStatResource {



    private final TableStatAggService tableStatAggService;

    public TableStatResource(TableStatAggService tableStatAggService) {
        this.tableStatAggService = tableStatAggService;
    }


    @GetMapping("/recent")
    public RestResponse<TableStatDTO> historyTableStat(@RequestParam(required = false) Instant startTime,
                                                       @RequestParam(required = false) Instant endTime,
                                                       @RequestParam("dataMediaPairId") Long dataMediaPairId) {
        return RestResponse.ok(tableStatAggService.recentTableStat(startTime,endTime,dataMediaPairId));
    }
}
